<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form class="formGroup" [formGroup]="formGroup">
  <lv-form-item>
    <lv-form-label lvRequired>
      {{'common_name_label'| i18n}}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="nameErrorTip">
      <input lv-input type="text" formControlName="name">
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{'common_cluster_label'| i18n}}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
      <lv-select formControlName="cluster" [lvOptions]="clusterOptions" lvValueKey="value" [lvDisabled]="rowData"
        lvFilterKey="label" lvFilterMode="contains" lvShowFilter></lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{'common_database_label'| i18n}}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
      <lv-select formControlName="database" [lvOptions]="databaseOptions" lvValueKey="value" [lvDisabled]="rowData"
        lvFilterKey="label" lvFilterMode="contains" lvShowFilter></lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label [lvColon]="colon" lvRequired>
      {{ 'protection_table_set_label' | i18n }}
    </lv-form-label>
    <lv-group *ngIf="rowData && deleteNum !== 0">
      <lv-alert lvType="warning">
        <span>{{ warningLabel }}</span>
        <span class='aui-link info' (click)='removeDelete()'>{{ 'protection_delete_label' | i18n}}</span>
      </lv-alert>
    </lv-group>
    <lv-group lvGutter="8px">
      <div class="hive-all-table hide-table-header-border-top">
        <div class="custom-table-header">
          {{ 'protection_selectable_table_label' | i18n }}
        </div>
        <lv-datatable [lvData]="tableData" #lvTable [lvScroll]="{ y: '660px' }" [lvPaginator]="pageA" lvSize="small"
          lvAsync="false" lvMultiGroup lvSelectionMode="multiple" [lvSelection]="selectionTable"
          (lvSelectionChange)="selectionChange($event)" lvCompareWith="name">
          <thead>
            <tr>
              <th lvShowCheckbox width="40px" [lvRowsData]="lvTable.renderData"></th>
              <th>
                <span>{{ 'common_name_label' | i18n }}</span>
              </th>
            </tr>
          </thead>
          <tbody>
            <ng-container *ngFor="let item of lvTable.renderData">
              <tr>
                <td width="40px" lvShowCheckbox [lvRowData]="item" [lvDisabled]="item.extendInfo?.isLocked === 'true'">
                </td>
                <td>
                  <div lvOverflow>{{ item.name }}</div>
                </td>
              </tr>
            </ng-container>
          </tbody>
        </lv-datatable>
        <ng-container *ngIf="totalTable > 0">
          <lv-paginator #pageA lvMode="simple" lvShowPageSizeOptions="false" class="table-paginator"
            [lvPageSize]="pageSize" [lvPageIndex]="pageIndex" [lvTotal]="totalTable"
            (lvPageChange)="pageChange($event)">
          </lv-paginator>
        </ng-container>
      </div>
      <div class="arrow-container">
        <i lv-icon="lv-icon-arrow-next" class="auto-protect-help" lvColorState="true"></i>
      </div>
      <div class="hive-selected-table">
        <lv-datatable [lvData]="selectedTableData" #lvSelectTable [lvScroll]="{ y: '660px' }" [lvPaginator]="pageS"
          lvSize="small">
          <thead>
            <tr>
              <th>
                <lv-group class="th-group" style="height: 24px;">
                  <lv-group lvGutter="8px">
                    <span class="aui-number-6">
                      {{ 'protection_selected_table_label' | i18n }}
                    </span>
                  </lv-group>
                  <span class="aui-link aui-number-6" (click)="clearSelected()">{{
                    'protection_clear_all_label' | i18n
                    }}</span>
                </lv-group>
              </th>
            </tr>
            <tr>
              <th>
                <span>
                  {{ 'common_name_label' | i18n }}
                </span>
              </th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let item of lvSelectTable.renderData">
              <td>
                <lv-group [ngClass]="{'th-group': !item?.hasDelete}">
                  <span class="name" lv-overflow>{{ item?.name | nil }}</span>
                  <span class="info-fail" *ngIf="item?.hasDelete"> {{
                    'protection_absent_label' | i18n}} </span>
                  <i class="icon" lv-icon="lv-icon-close"  lvColorState="true"
                    (click)="removeSingle(item)"></i>
                </lv-group>
              </td>
            </tr>
          </tbody>
        </lv-datatable>
        <ng-container *ngIf="selectedTableData.length > 0">
          <lv-paginator #pageS lvMode="simple" lvShowPageSizeOptions="false" class="table-paginator"
            [lvPageSize]="pageSize" [lvPageIndex]="pageIndexS" [lvTotal]="selectedTableData.length"
            (lvPageChange)="pageChangeS($event)">
          </lv-paginator>
        </ng-container>
      </div>
    </lv-group>
  </lv-form-item>
</lv-form>
